package longrise.phone.com.itssnew.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longrise.android.util.Util;
import com.longrise.android.widget.LLinearLayoutView;

/**
 * Created by chengsan on 17/7/7.
 */

public class LoadDialog extends Dialog {
    private Context context;
    private CustomProgressBar customProgressBar;

    public LoadDialog(Context context) {
        super(context, com.longrise.android.R.style.framework_longrise_alertdialog);
        this.context = context;
        init(context);
    }

    public LoadDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);

        init(context);
    }

    public LoadDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    public void init(Context context) {
        this.setCanceledOnTouchOutside(false);
        //this.setCancelable(false);
        this.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {

                if (null != customProgressBar) {
                    customProgressBar.onAnimationEnd();
                }
            }
        });
        int tempColor = Color.parseColor("#66E0E0E0");
        LLinearLayoutView linearLayoutView = new LLinearLayoutView(context);
        linearLayoutView.setBackgroundColor(tempColor, tempColor, tempColor,
                tempColor, tempColor, Util.dip2px(context, 10), 0, tempColor);
        linearLayoutView.setOrientation(LinearLayout.VERTICAL);
        linearLayoutView.setGravity(Gravity.CENTER);

        customProgressBar = new CustomProgressBar(context);
        linearLayoutView.addView(customProgressBar, Util.dip2px(context, 40),
                Util.dip2px(context, 40));

        TextView textView = new TextView(context);
        textView.setText("加载中...");
        textView.setTextSize(12);
        textView.setTextColor(Color.parseColor("#ffffff"));
        textView.setGravity(Gravity.CENTER);
        LinearLayout.LayoutParams textLP = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        textLP.topMargin = Util.dip2px(context, 8);
        linearLayoutView.addView(textView, textLP);

        int dialogWidth = Util.dip2px(context, 100);
        this.setContentView(linearLayoutView, new ViewGroup.LayoutParams(dialogWidth, dialogWidth));

    }

}
